package it.azienda.stampe.scriptlet;

import it.azienda.framework.persistenza.DAOConnectionSingleton;
import net.sf.jasperreports.engine.JRDefaultScriptlet;
import net.sf.jasperreports.engine.JRScriptletException;
import org.hibernate.Query;
import org.hibernate.Session;

public class SottoScorta extends JRDefaultScriptlet{
    
    public SottoScorta() {
        super();
    }
    
    public void afterDetailEval() throws JRScriptletException {
        Session sessione = (Session) DAOConnectionSingleton.newSession();
        Query q = null;
        String query = " select fornitori.ragioneSociale from BeanFornitore fornitori where fornitori.id = :idFornitore";
        
        Integer idFornitore = (Integer) this.getFieldValue("FORNITORE_ID");
        
        q = sessione.createQuery(query);
        q.setInteger("idFornitore", idFornitore.intValue());        
        String fornitore = (String) q.uniqueResult();       
        this.setVariableValue("fornitore", fornitore);      
    }
    
}